﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Specialized;
using WP.DB;
using WP.IM.DataEntity;
using WP.Commons;
using WP.Modules;

namespace WP.IM.DataAccess
{
    public class ImCategorySemiProductDAL : IDataAccess
    {
        #region Select List
        public string SQLList(int iParameter)
        {
            string strSQL = @"SELECT RecID,CategoryID,CategoryName,SemiCode,SemiName,ParentSemiCode,ParentSemiID,RecStamp,confirmed,confirmBy,confirmDate,WastageRate FROM imCategorySemiProduct Order by CategoryName,SemiCode";
            return strSQL;
        }
        #endregion

        #region Fields
        public string Fields
        {
            get
            {
                return @" CategoryID,CategoryName,SemiCode,SemiName,ParentSemiCode,ParentSemiID,confirmed,confirmBy,confirmDate,WastageRate,SemiLevel,Unit,Remark ";
            }
        }
        #endregion

        public bool Confirm(string strCateID)
        {
            DBAccess dbcon = new DBAccess(false, false);
            {
                string strSQL = "Update imCategorySemiProduct set confirmed= 1 ,confirmby='" + SysVar.UserName + "' , confirmdate=getdate() where CategoryID='" + strCateID + "'";
                dbcon.ExecuteSql(strSQL);
                AddApproHisory(strCateID, "审核", dbcon);
            }
            return true;
        }

        public bool unConfirm(string strCateID)
        {
            DBAccess dbcon = new DBAccess(false, false);
            {
                string strSQL = "Update imCategorySemiProduct set confirmed= 0 ,confirmby='' , confirmdate=null where CategoryID='" + strCateID + "'";
                dbcon.ExecuteSql(strSQL);
                AddApproHisory(strCateID, "反审核", dbcon);
            }
            return true;
        }

        public bool AddApproHisory(string strCateID , string strOperType, DBAccess dbcon)
        {
           
            string strSQL = "Insert  Into mApproHisory(UserName,OperDate,OperType,KeyID,TableType)";
            strSQL += "VALUES ( '" + SysVar.UserName + "', getdate(), '" + strOperType + "', '" + strCateID + "', '"+ frmApprovalHistory.TableType.CagtegorySemi +"' )";
            dbcon.ExecuteSql(strSQL);
            return true;
        }
    }
}
